home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / plotting / imagetoo / imagetl1.lha / Imagetool / src+obj / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-11  |  22.2 KB  |  793 lines

  1. /* cat > headers/init.h << "EOF" */
  2. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  3. /* init.h: header for init.c file            */
  4. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  5. /* SCCS information: %W%    %G% - NCSA */
  6.  
  7. #define init_h        1
  8.  
  9. #include "all.h"
  10. #include "icons.h"
  11. #include "newext.h"
  12.  
  13.     static char *Version="Imagetool 1.1";
  14.  
  15.     static int bghandler();
  16.     static Notify_value main_destroy_interposer();
  17.  
  18. /* EOF */
  19. /* cat > src+obj/init/bghandler.c << "EOF" */
  20. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  21. /* bghandler: (static) background event handler        */
  22. /*           for menu_panel                */
  23. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  24. /* SCCS information: %W%    %G% - NCSA */
  25.  
  26. /* #include "init.h" */
  27.  
  28. static
  29. bghandler (panel, event)
  30.     Panel           panel;
  31.     Event          *event;
  32. {
  33.     int             ex = event_x (event);
  34.     int             ey = event_y (event);
  35.     int             x, ix, k, n, nm = 8;
  36.  
  37.     x = 60;
  38.     ix = 100;
  39.     k = 30;
  40.     if (ex < x)
  41.         n = 1;
  42.     else if (ex > x + (nm - 1) * ix)
  43.         n = nm;
  44.     else
  45.     {
  46.         n = (ex - x) / ix + 1;
  47.         if (ex > n * ix + x - k)
  48.             n++;
  49.     }
  50.  
  51.         /* Some of these calls below have BOGUS arguments!!! - MK-C */
  52.  
  53.     switch (n)
  54.     {        /* show different menus according to position */
  55.         case 1:
  56.             if (display_panel_menu (Image, event, menu_panel, image_menu))
  57.                 load_proc (event, menu_get (image_menu, MENU_NTH_ITEM, 1));
  58.             break;
  59.         case 2:
  60.             if (display_panel_menu (Edit, event, menu_panel, edit_menu))
  61.                 edit_proc (event, menu_get (edit_menu, MENU_NTH_ITEM, 1));
  62.             break;
  63.         case 3:
  64.             if (display_panel_menu (Palette, event, menu_panel, pal_menu))
  65.                 pal_proc (event, menu_get (pal_menu, MENU_NTH_ITEM, 1));
  66.             break;
  67.         case 4:
  68.             if (display_panel_menu (Zoom, event, menu_panel, zoom_menu))
  69.                 zoom_proc (event, menu_get (zoom_menu, MENU_NTH_ITEM, 1));
  70.             break;
  71.         case 5:
  72.             if (display_panel_menu (Graph, event, menu_panel, graph_menu))
  73.                 plot_action (event, menu_get (graph_menu, MENU_NTH_ITEM, 1));
  74.             break;
  75.         case 6:
  76.             if (display_panel_menu (Ftp, event, menu_panel, ftp_menu))
  77.                 ftp_connect (event, menu_get (ftp_menu, MENU_NTH_ITEM, 1));
  78.             break;
  79.  
  80.         case 7:
  81.             if (display_panel_menu (Help, event, menu_panel, help_menu))
  82.                 help_proc (event, (Menu_item) menu_get (help_menu, MENU_NTH_ITEM, 1));
  83.             break;
  84.  
  85.         case 8:
  86.             if (display_panel_menu (Option, event, menu_panel, option_menu))
  87.                 set_defaults ();    /* menu item 1 - call set_defaults () */
  88.                 /* set_defaults (event, menu_get (option_menu, MENU_NTH_ITEM, 1)); */
  89.             break;
  90.         default:
  91.             break;
  92.     }
  93. }
  94. /* EOF */
  95. /* cat > src+obj/init/create_base.c << "EOF" */
  96. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  97. /* create_base: create base frame            */
  98. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  99. /* SCCS information: %W%    %G% - NCSA */
  100.  
  101. /* #include "init.h" */
  102.  
  103. create_base (argc, argv)
  104.     int             argc;
  105.     char           *argv[];
  106.  
  107. {
  108.     base = window_create (NULL, FRAME,
  109.                   FRAME_ICON, &frame_icon,
  110.                   WIN_WIDTH, 900,
  111.                   WIN_HEIGHT, 895,
  112.                   WIN_X, 0,
  113.                   WIN_Y, 0,
  114.                   FRAME_ARGS, argc, argv,
  115.                   WIN_ERROR_MSG, "Can't open window.",
  116.                   0);
  117.     set_frame_label (base);
  118.     (void) notify_interpose_destroy_func (base, main_destroy_interposer);
  119. }
  120. /* EOF */
  121. /* cat > src+obj/init/create_canvas.c << "EOF" */
  122. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  123. /* create_canvas: create canvas                */
  124. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  125. /* SCCS information: %W%    %G% - NCSA */
  126.  
  127. /* #include "init.h" */
  128.  
  129. create_canvas ()
  130. {
  131.     canvas = window_create (base, CANVAS,
  132.                 CANVAS_AUTO_SHRINK, FALSE,
  133.                 CANVAS_FIXED_IMAGE, FALSE,
  134.                 CANVAS_RETAINED, TRUE,
  135.                 CANVAS_WIDTH, 1150,
  136.                 CANVAS_HEIGHT, 900,
  137.                 WIN_BELOW, menu_panel,
  138.                 WIN_X, 0,
  139.                 WIN_VERTICAL_SCROLLBAR, scrollbar_create (0),
  140.                 WIN_HORIZONTAL_SCROLLBAR, scrollbar_create (0),
  141.                 WIN_EVENT_PROC, can_controller,
  142.                 0);
  143.     window_set (canvas,
  144.             WIN_CONSUME_PICK_EVENTS, LOC_DRAG, 0,
  145.             0);
  146.     pw = canvas_pixwin (canvas);
  147. }
  148. /* EOF */
  149. /* cat > src+obj/init/create_menus.c << "EOF" */
  150. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  151. /* create_menus: create menus                */
  152. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  153. /* SCCS information: %W%    %G% - NCSA */
  154.  
  155. /* #include "init.h" */
  156.  
  157. create_menus ()
  158. {
  159.     create_image_menu ();
  160.     create_pal_menu ();
  161.     create_edit_menu ();
  162.     create_zoom_menu ();
  163.     create_graph_menu ();
  164.     create_ftp_menu ();
  165.     create_help_menu ();
  166.     create_opt_menu ();
  167. }
  168. /* EOF */
  169. /* cat > src+obj/init/create_msgsw.c << "EOF" */
  170. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  171. /* create_msgsw: create message text subwindow        */
  172. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  173. /* SCCS information: %W%    %G% - NCSA */
  174.  
  175. /* #include "init.h" */
  176.  
  177. void 
  178. create_msgsw ()
  179. {
  180.     msgsw = window_create (base, TEXTSW,
  181.                    WIN_BELOW, panel,
  182.                     /* WIN_FONT, font_panel, */
  183.                     /* doesn't work even though the documentation says it should! */
  184.                    TEXTSW_READ_ONLY, TRUE,
  185.                    TEXTSW_LINE_BREAK_ACTION, TEXTSW_WRAP_AT_CHAR,
  186.                    WIN_ROWS, 3,
  187.                    WIN_X, 0,
  188.                    0);
  189.     return;
  190. }
  191. /* EOF */
  192. /* cat > src+obj/init/create_panel.c << "EOF" */
  193. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  194. /* create_panel: create non_menu panel            */
  195. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  196. /* SCCS information: %W%    %G% - NCSA */
  197.  
  198. /* #include "init.h" */
  199.  
  200. create_panel ()
  201. {
  202.     int             x, y, ix, iy;
  203.  
  204.         /* first major panel */
  205.  
  206.     panel = window_create (base, PANEL,
  207.                    WIN_BELOW, ttysw,
  208.                    WIN_HEIGHT, 130,
  209.                    WIN_X, 0,
  210.                    WIN_FONT, font_panel,
  211.                    0);
  212.     x = 50;
  213.     ix = 75;
  214.     y = 15;
  215.  
  216.         /* major buttons - always visible */
  217.  
  218.     panel_create_item (panel, PANEL_BUTTON,
  219.                PANEL_ITEM_X, x,
  220.                PANEL_ITEM_Y, y,
  221.                PANEL_LABEL_IMAGE, panel_button_image (panel, "Clear", 6, font_panel_button),
  222.                PANEL_NOTIFY_PROC, clear,
  223.                0);
  224.     panel_create_item (panel, PANEL_BUTTON,
  225.                PANEL_ITEM_X, x + ix,
  226.                PANEL_ITEM_Y, y,
  227.                PANEL_LABEL_IMAGE, panel_button_image (panel, "Cancel", 6, font_panel_button),
  228.                PANEL_NOTIFY_PROC, cancel,
  229.                0);
  230.     panel_create_item (panel, PANEL_BUTTON,
  231.                PANEL_ITEM_X, x + 2 * ix,
  232.                PANEL_ITEM_Y, y,
  233.                PANEL_LABEL_IMAGE, panel_button_image (panel, "Quit", 6, font_panel_button),
  234.                PANEL_NOTIFY_PROC, quit,
  235.                0);
  236.  
  237.         /* buttons for animation - visible only for animation */
  238.  
  239.     (void) create_animation_panel ();
  240.  
  241.         /* panel and menu objects for stacking */
  242.  
  243.     (void) create_stack_panel ();
  244.  
  245.         /* text item to enter user's input data */
  246.  
  247.     x += 4 * ix;
  248.     y = 5;
  249.     iy = 20;
  250.  
  251.     dir_board = panel_create_item (panel, PANEL_TEXT,
  252.                        PANEL_ITEM_X, x,
  253.                        PANEL_ITEM_Y, y,
  254.                        PANEL_LABEL_STRING, "Directory:",
  255.                        PANEL_VALUE_STORED_LENGTH, MAXNAMELEN - 1,
  256.                        PANEL_VALUE_DISPLAY_LENGTH, 40,
  257.                        PANEL_VALUE, current_dir,
  258.                        PANEL_LABEL_BOLD, TRUE,
  259.                        PANEL_MENU_TITLE_STRING, "Directory item",
  260.                        PANEL_MENU_CHOICE_STRINGS,
  261.                        "^N - Get directory name",
  262.                        "^C - Change directory",
  263.                        0,
  264.                        PANEL_MENU_CHOICE_FONTS,
  265.                        font_menu,
  266.                        font_menu,
  267.                        0,
  268.                        PANEL_MENU_CHOICE_VALUES,
  269.                        CTRL_N,
  270.                        CTRL_C,
  271.                        0,
  272.                        PANEL_SHOW_MENU, TRUE,
  273.                        PANEL_NOTIFY_LEVEL, PANEL_ALL,
  274.                        PANEL_NOTIFY_PROC, dir_board_proc,
  275.                        0);
  276.     image_board = panel_create_item (panel, PANEL_TEXT,
  277.                      PANEL_ITEM_X, x,
  278.                      PANEL_ITEM_Y, y + iy,
  279.                      PANEL_VALUE_STORED_LENGTH, MAXNAMELEN - 1,
  280.                      PANEL_VALUE_DISPLAY_LENGTH, 40,
  281.                      PANEL_LABEL_STRING, "Image:",
  282.                      PANEL_LABEL_BOLD, TRUE,
  283.                      PANEL_MENU_TITLE_STRING, "Filename item",
  284.                      PANEL_MENU_CHOICE_STRINGS,
  285.                      "^N - Get file name",
  286.                      "^L - Load image from file",
  287.                      "^A - Animate from files",
  288.                      "^C - Clear canvas",
  289.                      0,
  290.                      PANEL_MENU_CHOICE_FONTS,
  291.                      font_menu,
  292.                      font_menu,
  293.                      font_menu,
  294.                      font_menu,
  295.                      0,
  296.                      PANEL_MENU_CHOICE_VALUES,
  297.                      CTRL_N,
  298.                      CTRL_L,
  299.                      CTRL_A,
  300.                      CTRL_C,
  301.                      0,
  302.                      PANEL_SHOW_MENU, TRUE,
  303.                      PANEL_NOTIFY_LEVEL, PANEL_ALL,
  304.                      PANEL_NOTIFY_PROC, image_board_proc,
  305.                      0);
  306.     load_toggle = panel_create_item (panel, PANEL_CYCLE,
  307.                      PANEL_ITEM_X, x + 100,
  308.                      PANEL_ITEM_Y, y + 2 * iy,
  309.                      PANEL_LABEL_STRING, "Loading?:",
  310.                      PANEL_LABEL_BOLD, TRUE,
  311.                      PANEL_CHOICE_STRINGS,
  312.                          "First (whatever) & palette (if any)",
  313.                          "First RIS8 image & palette (HDF)",
  314.                          "First SDS 2D-data (HDF)",
  315.                          "First (whatever) only",
  316.                          "First RIS8 image only (HDF)",
  317.                          0,
  318.                      PANEL_MENU_CHOICE_FONTS,
  319.                          font_menu,
  320.                          font_menu,
  321.                          font_menu,
  322.                         font_menu,
  323.                          font_menu,
  324.                          font_menu,
  325.                          0,
  326.                      PANEL_SHOW_MENU, TRUE,
  327.                      0);
  328.     xdim_item = panel_create_item (panel, PANEL_TEXT,
  329.                        PANEL_ITEM_X, x + 100,
  330.                        PANEL_ITEM_Y, y + 3 * iy,
  331.                        PANEL_VALUE_STORED_LENGTH, 5,
  332.                        PANEL_VALUE_DISPLAY_LENGTH, 5,
  333.                        PANEL_LABEL_STRING, "Xdim:",
  334.                        PANEL_LABEL_BOLD, TRUE,
  335.                        PANEL_MENU_CHOICE_STRINGS,
  336.                        "X dimension (integer)", 0,
  337.                        PANEL_MENU_CHOICE_FONTS,
  338.                        font_menu,
  339.                        0,
  340.                        PANEL_SHOW_MENU, TRUE,
  341.                        0);
  342.     ydim_item = panel_create_item (panel, PANEL_TEXT,
  343.                        PANEL_ITEM_X, x + 250,
  344.                        PANEL_ITEM_Y, y + 3 * iy,
  345.                        PANEL_VALUE_STORED_LENGTH, 5,
  346.                        PANEL_VALUE_DISPLAY_LENGTH, 5,
  347.                        PANEL_LABEL_STRING, "Ydim:",
  348.                        PANEL_LABEL_BOLD, TRUE,
  349.                        PANEL_MENU_CHOICE_STRINGS,
  350.                        "Y dimension (integer)",
  351.                        0,
  352.                        PANEL_MENU_CHOICE_FONTS,
  353.                        font_menu,
  354.                        0,
  355.                        PANEL_SHOW_MENU, TRUE,
  356.                        0);
  357.     pal_board = panel_create_item (panel, PANEL_TEXT,
  358.                        PANEL_ITEM_X, x,
  359.                        PANEL_ITEM_Y, y + 4 * iy,
  360.                        PANEL_VALUE_STORED_LENGTH, MAXNAMELEN - 1,
  361.                        PANEL_VALUE_DISPLAY_LENGTH, 40,
  362.                        PANEL_LABEL_STRING, "Palette:",
  363.                        PANEL_LABEL_BOLD, TRUE,
  364.                        PANEL_MENU_TITLE_STRING, "Palette item",
  365.                        PANEL_MENU_CHOICE_STRINGS,
  366.                                "^N - Get file name",
  367.                                "^L - Load palette from file",
  368.                                "^R - Restore previous palette",
  369.                                "^S - Show palette",
  370.                                0,
  371.                        PANEL_MENU_CHOICE_FONTS,
  372.                                font_menu,
  373.                                font_menu,
  374.                                font_menu,
  375.                                0,
  376.                        PANEL_MENU_CHOICE_VALUES,
  377.                                CTRL_N,
  378.                                CTRL_L,
  379.                                CTRL_R,
  380.                                CTRL_S,
  381.                                0,
  382.                        PANEL_SHOW_MENU, TRUE,
  383.                        PANEL_NOTIFY_LEVEL, PANEL_ALL,
  384.                        PANEL_NOTIFY_PROC, pal_board_proc,
  385.                        0);
  386.     SDS_toggle = panel_create_item (panel, PANEL_CYCLE,
  387.                     PANEL_ITEM_X, x,
  388.                     PANEL_ITEM_Y, y + 5 * iy,
  389.                     PANEL_LABEL_STRING, "SDS Scaling:",
  390.                     PANEL_LABEL_BOLD, TRUE,
  391.                     PANEL_CHOICE_STRINGS,
  392.                         "Use popup dialog window",
  393.                         "Linear, data max & min",
  394.                         "Log, data max & min",
  395.                         0,
  396.                     PANEL_MENU_CHOICE_FONTS,
  397.                          font_menu,
  398.                          font_menu,
  399.                          font_menu,
  400.                          0,
  401.                     PANEL_SHOW_MENU, TRUE,
  402.                     0);
  403. }
  404. /* EOF */
  405. /* cat > src+obj/init/create_panel_menu.c << "EOF" */
  406. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  407. /* create_panel_menu: create panel with menu items    */
  408. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  409. /* SCCS information: %W%    %G% - NCSA */
  410.  
  411. /* #include "init.h" */
  412.  
  413. void 
  414. create_panel_menu ()
  415. {
  416.     int             x, y, ix, iy;
  417.  
  418.  /* Menu items */
  419.  
  420.     menu_panel = window_create (base, PANEL,
  421.                     WIN_BELOW, msgsw,
  422.                     WIN_HEIGHT, 25,
  423.                     WIN_X, 0,
  424.                     PANEL_BACKGROUND_PROC, bghandler,
  425.                     /* allows one to pick a menu when the event
  426.                        (click rightmost) is on the background of the panel. */
  427.                     WIN_FONT, font_panel,
  428.                     0);
  429.  
  430.     x = 60;
  431.     ix = 100;
  432.     y = 3;
  433.  
  434.     Image = panel_create_item (menu_panel, PANEL_BUTTON,
  435.                    PANEL_ITEM_X, x,
  436.                    PANEL_ITEM_Y, y,
  437.                    PANEL_LABEL_IMAGE, panel_button_image (panel, "Image", 6, font_panel_button),
  438.                    PANEL_EVENT_PROC, image_handler,
  439.                    0);
  440.  
  441.     Edit = panel_create_item (menu_panel, PANEL_BUTTON,
  442.                   PANEL_ITEM_X, x + ix,
  443.                   PANEL_ITEM_Y, y,
  444.                   PANEL_LABEL_IMAGE, panel_button_image (panel, "Edit", 6, font_panel_button),
  445.                   PANEL_EVENT_PROC, edit_handler,
  446.                   0);
  447.  
  448.     Palette = panel_create_item (menu_panel, PANEL_BUTTON,
  449.                      PANEL_ITEM_X, x + 2 * ix,
  450.                      PANEL_ITEM_Y, y,
  451.                      PANEL_LABEL_IMAGE, panel_button_image (panel, "Palette", 6, font_panel_button),
  452.                      PANEL_EVENT_PROC, pal_handler,
  453.                      0);
  454.  
  455.     Zoom = panel_create_item (menu_panel, PANEL_BUTTON,
  456.                   PANEL_ITEM_X, x + 3 * ix,
  457.                   PANEL_ITEM_Y, y,
  458.                   PANEL_LABEL_IMAGE, panel_button_image (panel, "Zoom", 6, font_panel_button),
  459.                   PANEL_EVENT_PROC, zoom_handler,
  460.                   0);
  461.  
  462.     Graph = panel_create_item (menu_panel, PANEL_BUTTON,
  463.                    PANEL_ITEM_X, x + 4 * ix,
  464.                    PANEL_ITEM_Y, y,
  465.                    PANEL_LABEL_IMAGE, panel_button_image (panel, "Graph", 6, font_panel_button),
  466.                    PANEL_EVENT_PROC, plot_handler,
  467.                    0);
  468.  
  469.     Ftp = panel_create_item (menu_panel, PANEL_BUTTON,
  470.                  PANEL_ITEM_X, x + 5 * ix,
  471.                  PANEL_ITEM_Y, y,
  472.                  PANEL_LABEL_IMAGE, panel_button_image (panel, "FTP", 6, font_panel_button),
  473.                  PANEL_EVENT_PROC, ftp_handler,
  474.                  0);
  475.  
  476.     Help = panel_create_item (menu_panel, PANEL_BUTTON,
  477.                   PANEL_ITEM_X, x + 6 * ix,
  478.                   PANEL_ITEM_Y, y,
  479.                   PANEL_LABEL_IMAGE, panel_button_image (panel, "Help", 6, font_panel_button),
  480.                   PANEL_EVENT_PROC, help_handler,
  481.                   0);
  482.  
  483.     Option = panel_create_item (menu_panel, PANEL_BUTTON,
  484.                     PANEL_ITEM_X, x + 7 * ix,
  485.                     PANEL_ITEM_Y, y,
  486.                     PANEL_LABEL_IMAGE, panel_button_image (panel, "Option", 6, font_panel_button),
  487.                     PANEL_EVENT_PROC, opt_handler,
  488.                     0);
  489.  
  490. }
  491. /* EOF */
  492. /* cat > src+obj/init/create_ttysw.c << "EOF" */
  493. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  494. /* create_ttysw: create tty subwindow            */
  495. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  496. /* SCCS information: %W%    %G% - NCSA */
  497.  
  498. /* #include "init.h" */
  499.  
  500. create_ttysw ()
  501. {
  502.     static char    *my_argv[] = {"csh", 0};
  503.  
  504.     ttysw = window_create (base, TTY,
  505.                    WIN_ROWS, 6,        /* 6 rows are needed for vi to work! */
  506.                    TTY_ARGV, my_argv,    /* be sure that csh is run. */
  507.                    0);
  508. }
  509. /* EOF */
  510. /* cat > src+obj/init/init_env.c << "EOF" */
  511. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  512. /* init_env: try to get help file directory, default    */
  513. /*         default palette, and image directory.    */
  514. /*         The help file directory MUST be in the    */
  515. /*         users default database, i.e.         */
  516. /*         $HOME/.defaults maintained by        */
  517. /*         defaultsedit. It must exist. Otherwise,    */
  518. /*         ImageTool will not start. The default    */
  519. /*         default palette filename and image        */
  520. /*         directory may optionally exist in the    */
  521. /*         users default database. If the default    */
  522. /*         palette filename is not there or is in    */
  523. /*         error no default palette is assigned.    */
  524. /*         Otherwise, this palette is loaded. If from    */
  525. /*         an HDF file the first palette in the file    */
  526. /*         is used. If the image directory is not    */
  527. /*         there or is in error the current directory    */
  528. /*         is used.                    */
  529. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  530. /* SCCS information: %W%    %G% - NCSA */
  531.  
  532. /* #include "init.h" */
  533.  
  534. init_env ()
  535. {
  536. /* Implementation note(s):
  537.  
  538.     1. Since calling system() invokes the shell any "wildcard" and
  539.        multiple arguments will be handled by the call. Remember
  540.        system() invokes the Bourne shell. So, call csh explicitly
  541.        to get the more powerful "wildcard" features.
  542. */
  543.     int             err;
  544.     char           *p_defaultstr;
  545.     char            tmpname[MAXNAMELEN];
  546.  
  547.         /* get help directory - must be in defaults database */
  548.     if ((p_defaultstr = get_defaults (DEFAULT_HELP_DIR)) == NULL)
  549.     {
  550.         msg2_stderr ("No help directory, ImageTool terminated.",
  551.                  "Check defaults database with defaultsedit.");
  552.         exit (-1);
  553.     }
  554.     sprintf (wkstr, "csh -fc \"test -d '%s'\"", p_defaultstr);
  555.     if (check_system (wkstr))    /* 0 exit status means true */
  556.     {
  557.         sprintf (wkstr, "Dir = %s", p_defaultstr);
  558.         msg2_stderr ("Help directory bad or does not exist. ImageTool terminated.", wkstr);
  559.         exit (-1);
  560.     }
  561.     strcpy (tmpname, p_defaultstr);
  562.     if ((err = get_abspathname (tmpname, MAXNAMELEN, TYPE_DIR)))    /* error should not occur */
  563.     {
  564.         sprintf (wkstr, "Internal error (%d): While resolving help directory. ImageTool terminated. Report bug!", err);
  565.         sprintf (wkstr2, "Dir = %s", p_defaultstr);
  566.         msg2_stderr (wkstr, wkstr2);
  567.         exit (-1);
  568.     }
  569.     strcpy (help_dir, tmpname);
  570.     (void) chdir (help_dir);
  571.     (void) getwd (help_dir);
  572.     (void) chdir (current_dir);
  573.  
  574.         /* get default palette - optionally in the defaults database
  575.                      use no palette if none given. */
  576.  
  577.     if ((p_defaultstr = get_defaults (DEFAULT_PALETTE_FILE)) == NULL)
  578.     {
  579.         msg_write ("Warning: No defaults palette file. None set.");
  580.         strcpy (default_cdir, current_dir);
  581.     }
  582.     else
  583.     {
  584.         strcpy (default_pal.fn, p_defaultstr);
  585.         if (load_pal (DEFAULT))
  586.         {        /* if error then null out */
  587.             default_pal.fn[0] = '\0';
  588.             default_pal.type = PAL_UNKNOWN;
  589.             default_pal.num = 0;
  590.         }
  591.     }
  592.  
  593.         /* get image directory - optionally in the defaults database
  594.                      use the current directory if none
  595.                      given. */
  596.         /* current_dir set in init_vars.c */
  597.  
  598.     if ((p_defaultstr = get_defaults (DEFAULT_IMAGE_DIR)) == NULL)
  599.     {
  600.         msg_write ("Warning: No defaults image directory. Current directory used.");
  601.         strcpy (default_cdir, current_dir);
  602.     }
  603.     else
  604.     {
  605.         sprintf (wkstr, "csh -cf \"test -d '%s'\"", p_defaultstr);
  606.         if (check_system (wkstr))
  607.         {        /* 0 exit status means true */
  608.             msg_write ("Warning: Bad defaults image directory. Current directory used.");
  609.             strcpy (default_cdir, current_dir);
  610.         }
  611.         else
  612.         {        /* fully resolve pathname */
  613.             strcpy (tmpname, p_defaultstr);
  614.             if ((err = get_abspathname (tmpname, MAXNAMELEN, TYPE_DIR)))
  615.             {        /* error should not occur */
  616.                 sprintf (wkstr, "Internal error (%d): While resolving default image directory. Report bug! Current directory used\n.       Dir = %s", err, p_defaultstr);
  617.                 msg_write (wkstr);
  618.                 strcpy (default_cdir, current_dir);
  619.             }
  620.             else
  621.             {
  622.                 strcpy (default_cdir, tmpname);
  623.                 strcpy (current_dir, default_cdir);
  624.             }
  625.         }
  626.     }
  627.     (void) chdir (current_dir);
  628.     (void) getwd (current_dir);
  629.     strcpy (default_cdir, current_dir);
  630.     panel_set_value (dir_board, current_dir);
  631.     set_frame_label (base);
  632.     return (0);
  633. }
  634. /* EOF */
  635. /* cat > src+obj/init/init_vars.c << "EOF" */
  636. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  637. /* init_vars: initialize all variables            */
  638. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  639. /* SCCS information: %W%    %G% - NCSA */
  640.  
  641. /* #include "init.h" */
  642.  
  643. init_vars ()
  644. {
  645.     char           *font_panel_file, *font_panel_button_file, *font_menu_file;
  646.  
  647.         /* reset flags */
  648.     rev_image = 0;
  649.     dark_bg = 0;
  650.  
  651.     startx = starty = ORIGINXY;
  652.     main_quit = 0;
  653.     clear_request = 0;
  654.     pos_picked = 0;
  655.  
  656.     graph_mode = PLOT_NONE;
  657.     color_edit_mode = CEDIT_NONE;
  658.  
  659.     getloop_go = 0;
  660.     animation_go = 0;
  661.     pause_request = 0;
  662.     repeat_index = 0;
  663.     square_drawn = line_drawn = 0;
  664.     first_point = 0;
  665.     middle_button_down = 0;
  666.     linear_scaling = 1;
  667.  
  668.         /* initialize relevant parts of curr_image */
  669.     curr_image.img_name[0] = '\0';
  670.     curr_image.pal_name[0] = '\0';
  671.     curr_image.startx = 0;
  672.     curr_image.starty = 0;
  673.     curr_image.org_xdim = 0;
  674.     curr_image.org_ydim = 0;
  675.     curr_image.xdim = 0;
  676.     curr_image.ydim = 0;
  677.     curr_image.image = NULL;
  678.     curr_image.expanded = 0;
  679.     curr_image.zoomx = 0;
  680.     curr_image.zoomy = 0;
  681.     curr_image.in_use = 0;
  682.     curr_image.cutout = 0;
  683.     
  684.         /* initialize palettes */
  685.     color_index = LUTSIZE;
  686.  
  687.     last_pal.fn[0] = '\0';
  688.     last_pal.type = PAL_UNKNOWN;
  689.     last_pal.num = 0;
  690.  
  691.     curr_pal.fn[0] = '\0';
  692.     curr_pal.type = PAL_UNKNOWN;
  693.     curr_pal.num = 0;
  694.  
  695.     default_pal.fn[0] = '\0';
  696.     default_pal.type = PAL_UNKNOWN;
  697.     default_pal.num = 0;
  698.  
  699.     printer[0] = '\0';
  700.  
  701.     loop_zoomed = 0;
  702.  
  703.     flinear = 1;
  704.  
  705.         /* reset sub frame pointers */
  706.     plot_window = NULL;
  707.     scale_box = NULL;
  708.     help_window = NULL;
  709.     imagesave_box = NULL;
  710.     palsave_box = NULL;
  711.  
  712.         /* get current working directory */
  713.     getwd (current_dir);
  714.  
  715.         /* get fonts */
  716.     if ((font_panel_file = get_defaults (DEFAULT_FONT_PANEL)) == NULL)
  717.     {
  718.         msg2_stderr ("No panel font file, ImageTool terminated.",
  719.                  "Check defaults database with defaultsedit.");
  720.         exit (-1);
  721.     }
  722.     if ((font_panel = pf_open (font_panel_file)) == NULL)
  723.     {
  724.         sprintf (wkstr, "File = %s, check defaults database with defaultsedit.", font_panel_file);
  725.         msg2_stderr ("Could not load panel font file, ImageTool terminated.", wkstr);
  726.         exit (-1);
  727.     }
  728.  
  729.     if ((font_panel_button_file = get_defaults (DEFAULT_FONT_PANEL_BUTTON)) == NULL)
  730.     {
  731.         msg2_stderr ("No panel button font file, ImageTool terminated.",
  732.                  "Check defaults database with defaultsedit.");
  733.         exit (-1);
  734.     };
  735.     if ((font_panel_button = pf_open (font_panel_button_file)) == NULL)
  736.     {
  737.         sprintf (wkstr, "File = %s, check defaults database with defaultsedit.", font_panel_file);
  738.         msg2_stderr ("Could not load panel button font file, ImageTool terminated", wkstr);
  739.         exit (-1);
  740.     }
  741.  
  742.     if ((font_menu_file = get_defaults (DEFAULT_FONT_MENU)) == NULL)
  743.     {
  744.         msg2_stderr ("No menu font file, ImageTool terminated.",
  745.                  "Check defaults database with defaultsedit.");
  746.         exit (-1);
  747.     };
  748.     if ((font_menu = pf_open (font_menu_file)) == NULL)
  749.     {
  750.         sprintf (wkstr, "File = %s, check defaults database with defaultsedit.", font_panel_file);
  751.         msg2_stderr ("Could not load menu font file, ImageTool terminated", wkstr);
  752.         exit (-1);
  753.     }
  754. }
  755. /* EOF */
  756. /* cat > src+obj/init/main_destroy_interposer.c << "EOF" */
  757. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  758. /* main_destroy_interposer: (static) destroy the base   */
  759. /*                frame            */
  760. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  761. /* SCCS information: %W%    %G% - NCSA */
  762.  
  763. /* #include "init.h" */
  764.  
  765. static          Notify_value
  766. main_destroy_interposer (frame, status)
  767.     Frame           frame;
  768.     Destroy_status  status;
  769. {
  770.     if (status != DESTROY_CHECKING)
  771.     {
  772.         main_quit = 1;
  773.         main_cleanup ();
  774.     }
  775.     return (notify_next_destroy_func (frame, status));
  776. }
  777. /* EOF */
  778. /* cat > src+obj/init/set_frame_label.c << "EOF" */
  779. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  780. /* set_frame_label: set the frame label            */
  781. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  782. /* SCCS information: %W%    %G% - NCSA */
  783.  
  784. /* #include "init.h" */
  785.  
  786. set_frame_label (frame)
  787.     Frame           frame;
  788. {
  789.     sprintf (wkstr, "%s   ---  Current directory: %s\n", Version, current_dir);
  790.     window_set (frame, FRAME_LABEL, wkstr, 0);
  791. }
  792. /* EOF */
  793.